/**
 * Created by gaoyj on 2018/6/28.
 */
window.onload = function (ev) {
    topbar.hide();
};
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
if (month < 10) {
    month = "0" + month;
}
if (day < 10) {
    day = "0" + day;
}
var _start = myDate.getFullYear() + '-' + month + '-' + day;
var _end = myDate.getFullYear() + '-' + month + '-' + day;
laydate.render({
    elem: '#startTime'
});
laydate.render({
    elem: '#endTime' //指定元素
});
$("#startTime").val(_start);
$("#endTime").val(_end);
buttonShiro("export_Role");
var adminRole = roleCheck();
$('#dataTable').bootstrapTable({
    url: '/finance/querySupplyDailySheetPage',
    height: $(window).height() - 200,
    pageSize: 30,
    pagination: true,
    pageList: [30, 50, 100],
    clickToSelect: true,
    queryParams: queryParams,
    uniqueId: 'id',
    queryParamsType: '',
    sidePagination: 'server',
    responseHandler: function (res) {
        return {
            "total": res.total,
            "rows": res.resultList
        };
    },
    onClickRow: function (row) {
        if (row.userAccount != null && row.userAccount != '') {
            $("#account_field"+row.id).html(row.userAccount);
        }
    },
    columns: [[
        {
            width: '3px',
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        },
        {field: 'startTime', title: '日期', width: 80, align: 'center'},
        {field: 'userAccount', title: '会员编号', width: 90, align: 'center',
            formatter: function (v, o) {
                return copyAddon(v) + (adminRole == 1 ? v :userAccountHidden(o.userAccount, o.id));
            }},
        {field: 'userName', title: '会员名称', width: 70, align: 'center'},
        {field: 'beginBalance', title: '期初余额', width: 65, align: 'center'},
        {field: 'endBalance', title: '期末余额', width: 65, align: 'center'},
        {field: 'defference', title: '差额', width: 40, align: 'center'},
        {field: 'withdrawMoney', title: '提现</br>至支付宝', width: 60, align: 'center'},
        {field: 'withdrawBankMoney', title: '提现</br>至银行', width: 60, align: 'center'},
        {field: 'servicePrice', title: '提现</br>手续费', width: 60, align: 'center'},
        {field: 'mobileEntryMoney', title: '移动</br>入账金额', width: 60, align: 'center'},
        {field: 'unicomEntryMoney', title: '联通</br>入账金额', width: 60, align: 'center'},
        {field: 'telecomEntryMoney', title: '电信</br>入账金额', width: 60, align: 'center'},
        {field: 'entryMoney', title: '入账金额', width: 65, align: 'center'},
        {field: 'mobileSuccessFace', title: '移动</br>成功面值', width: 60, align: 'center'},
        {field: 'unicomSuccessFace', title: '联通</br>成功面值', width: 60, align: 'center'},
        {field: 'telecomSuccessFace', title: '电信</br>成功面值', width: 60, align: 'center'},
        {field: 'summaryFace', title: '汇总面值', width: 60, align: 'center'},
        {field: 'fixMoney', title: '补结金额</br>(三网)', width: 60, align: 'center'},
        {field: 'rebate', title: '服务费', width: 60, align: 'center'},
        {field: 'manualRefund', title: '提现失败手动退款', width: 60, align: 'center'}
        // {field: 'recommendRebate', title: '推荐返利', width: 60, align: 'center'}
    ]]
});

$("#search").click(function () {
    var timeAdd = new Date($("#startTime").val());
    var timeEnd = new Date($("#endTime").val());
    if (timeAdd > timeEnd) {
        layer.msg("开始时间不能大于结束时间");
        return false;
    }
    $("#dataTable").bootstrapTable("refresh");
});
//下载
$("#export").click(function () {
    window.location.href = "/finance/dailyReportdownLoad?" + $("#userSupplyCardReportForm").serialize()
})

function queryParams(params) {
    return {
        size: params.pageSize,
        page: params.pageNumber,
        startTime: $("#startTime").val(),
        endTime: $("#endTime").val(),
        userAccount: $("#userAccount").val()
    };
}